mm: make pages allocated with MEMF_no_refcount safe to assign
authorPaul Durrant <pdurrant@amazon.com>
Thu, 30 Jan 2020 12:56:42 +0000 (12:56 +0000)
committerAndrew Cooper <andrew.cooper3@citrix.com>
Fri, 14 Feb 2020 14:24:50 +0000 (14:24 +0000)
commitc793d13944b45d7a655ad230717cd5f335101920
tree6c46f74b5d367d4dd52342578d7aa713e3fe550f
parent37663f36df8975b9fbba18f5c392bd6ac8edd64c
mm: make pages allocated with MEMF_no_refcount safe to assign

Currently it is unsafe to assign a domheap page allocated with
MEMF_no_refcount to a domain because the domain't 'tot_pages' will not
be incremented, but will be decrement when the page is freed (since
free_domheap_pages() has no way of telling that the increment was skipped).

This patch allocates a new 'count_info' bit for a PGC_extra flag
which is then used to mark pages when alloc_domheap_pages() is called
with MEMF_no_refcount. assign_pages() because it still needs to call
domain_adjust_tot_pages() to make sure the domain is appropriately
referenced. Hence it is modified to do that for PGC_extra pages even if it
is passed MEMF_no_refount.

The number of PGC_extra pages assigned to a domain is tracked in a new
'extra_pages' counter, which is then subtracted from 'total_pages' in
the domain_tot_pages() helper. Thus 'normal' page assignments will still
be appropriately checked against 'max_pages'.

Signed-off-by: Paul Durrant <pdurrant@amazon.com>
Reviewed-by: Jan Beulich <jbeulich@suse.com>
Acked-by: Julien Grall <julien@xen.org>
Acked-by: George Dunlap <George.Dunlap@eu.citrix.com>
xen/arch/x86/mm.c
xen/common/page_alloc.c
xen/include/asm-arm/mm.h
xen/include/asm-x86/mm.h
xen/include/xen/sched.h